package system.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;

import DB.DB_connection_pool;
import bean.Credit_parameter;

public class Weight_edit extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		JSONObject jsonObj = new JSONObject();
		
		if((int)(request.getSession().getAttribute("weight_Jurisdiction")) == 1){
		
		JSONObject data = new JSONObject(request.getParameter("data"));
		
		Credit_parameter.setLogon_1(data.getInt("logon_1"));
		Credit_parameter.setLogon_2(data.getInt("logon_2"));
		Credit_parameter.setLogon_3(data.getInt("logon_3"));
		Credit_parameter.setLogon_4(data.getInt("logon_4"));
		Credit_parameter.setLogon_5(data.getInt("logon_5"));
		Credit_parameter.setLogon_6(data.getInt("logon_6"));
		Credit_parameter.setLogon_7(data.getInt("logon_7"));
		Credit_parameter.setPraise(data.getInt("praise"));
		Credit_parameter.setReview(data.getInt("review"));
		Credit_parameter.setAttention(data.getInt("attention"));
		Credit_parameter.setForward(data.getInt("forward"));
		Credit_parameter.setPublish_dynamic(data.getInt("publish_dynamic"));
		Credit_parameter.setAttention_log(data.getInt("attention_log"));
		Credit_parameter.setPraise_log(data.getInt("praise_log"));
		Credit_parameter.setForward_log(data.getInt("forward_log"));
		Credit_parameter.setReview_log(data.getInt("review_log"));
		Credit_parameter.setMatch_level_1(data.getInt("match_level_1"));
		Credit_parameter.setMatch_level_2(data.getInt("match_level_2"));
		Credit_parameter.setMatch_level_3(data.getInt("match_level_3"));
		Credit_parameter.setMatch_level_4(data.getInt("match_level_4"));
		Credit_parameter.setProfession_running_record_weight(data.getDouble("profession_running_record_weight"));
		Credit_parameter.setProfession_running_result_weight(data.getDouble("profession_running_result_weight"));
		Credit_parameter.setProfession_swimming_record_weight(data.getDouble("profession_swimming_record_weight"));
		Credit_parameter.setProfession_swimming_result_weight(data.getDouble("profession_swimming_result_weight"));
		Credit_parameter.setProfession_basketball_assist_weight(data.getDouble("profession_basketball_assist_weight"));
		Credit_parameter.setProfession_basketball_ponit_weight(data.getDouble("profession_basketball_ponit_weight"));
		Credit_parameter.setProfession_basketball_rebound_weight(data.getDouble("profession_basketball_rebound_weight"));
		Credit_parameter.setProfession_basketball_record_weight(data.getDouble("profession_basketball_record_weight"));
		Credit_parameter.setProfession_basketball_result_weight(data.getDouble("profession_basketball_result_weight"));
		Credit_parameter.setProfession_basketball_steal_weight(data.getDouble("profession_basketball_steal_weight"));
		Credit_parameter.setDynamic_equilibrium(data.getInt("dynamic_equilibrium"));
		
		String update_sql = "update credit_pram set ";
		update_sql = update_sql+"logon_1 = '"+data.getInt("logon_1")+"' , ";
		update_sql = update_sql+"logon_2 = '"+data.getInt("logon_2")+"' , ";
		update_sql = update_sql+"logon_3 = '"+data.getInt("logon_3")+"' , ";
		update_sql = update_sql+"logon_4 = '"+data.getInt("logon_4")+"' , ";
		update_sql = update_sql+"logon_5 = '"+data.getInt("logon_5")+"' , ";
		update_sql = update_sql+"logon_6 = '"+data.getInt("logon_6")+"' , ";
		update_sql = update_sql+"logon_7 = '"+data.getInt("logon_7")+"' , ";
		update_sql = update_sql+"praise = '"+data.getInt("praise")+"' , ";
		update_sql = update_sql+"review = '"+data.getInt("review")+"' , ";
		update_sql = update_sql+"attention = '"+data.getInt("attention")+"' , ";
		update_sql = update_sql+"forward = '"+data.getInt("forward")+"' , ";
		update_sql = update_sql+"publish_dynamic = '"+data.getInt("publish_dynamic")+"' , ";
		update_sql = update_sql+"attention_log = '"+data.getInt("attention_log")+"' , ";
		update_sql = update_sql+"praise_log = '"+data.getInt("praise_log")+"' , ";
		update_sql = update_sql+"forward_log = '"+data.getInt("forward_log")+"' , ";
		update_sql = update_sql+"review_log = '"+data.getInt("review_log")+"' , ";
		update_sql = update_sql+"match_level_1 = '"+data.getInt("match_level_1")+"' , ";
		update_sql = update_sql+"match_level_2 = '"+data.getInt("match_level_2")+"' , ";
		update_sql = update_sql+"match_level_3 = '"+data.getInt("match_level_3")+"' , ";
		update_sql = update_sql+"match_level_4 = '"+data.getInt("match_level_4")+"' , ";
		update_sql = update_sql+"profession_running_record_weight = '"+data.getDouble("profession_running_record_weight")+"' , ";
		update_sql = update_sql+"profession_running_result_weight = '"+data.getDouble("profession_running_result_weight")+"' , ";
		update_sql = update_sql+"profession_swimming_record_weight = '"+data.getDouble("profession_swimming_record_weight")+"' , ";
		update_sql = update_sql+"profession_swimming_result_weight = '"+data.getDouble("profession_swimming_result_weight")+"' , ";
		update_sql = update_sql+"profession_basketball_assist_weight = '"+data.getDouble("profession_basketball_assist_weight")+"' , ";
		update_sql = update_sql+"profession_basketball_ponit_weight = '"+data.getDouble("profession_basketball_ponit_weight")+"' , ";
		update_sql = update_sql+"profession_basketball_rebound_weight = '"+data.getDouble("profession_basketball_rebound_weight")+"' , ";
		update_sql = update_sql+"profession_basketball_record_weight = '"+data.getDouble("profession_basketball_record_weight")+"' , ";
		update_sql = update_sql+"profession_basketball_result_weight = '"+data.getDouble("profession_basketball_result_weight")+"' , ";
		update_sql = update_sql+"profession_basketball_steal_weight = '"+data.getDouble("profession_basketball_steal_weight")+"' , ";
		update_sql = update_sql+"dynamic_equilibrium = '"+data.getInt("dynamic_equilibrium")+"'";
		
		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement ps_update = conn.prepareStatement(update_sql);
			ps_update.executeUpdate();
			
			ps_update.close();
			conn.close();
			jsonObj.put("result", true);
		} catch (SQLException e) {
			jsonObj.put("result", false);
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}else{
			jsonObj.put("result", false);
		}
		out.print(jsonObj.toString());
		
	}

}
